package com.ship.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ship.common.core.base.Page;
import com.ship.common.core.enums.NotifyType;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.system.buesiness.MoveCloudBusiness;
import com.ship.system.domain.SysMessageConfig;
import com.ship.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

/**
 * 系统消息配置管理
 * 
 * @author zhangyh
 */
@RestController
@RequestMapping("/message/config")
@Api(value = "sysMessageConfig", tags = "系统消息配置管理")
public class SysMessageConfigController
{
    @Autowired
    private SysMessageConfigService sysMessageConfigService;

    @Autowired
    private MoveCloudBusiness moveCloudBusiness;

    /**
     * 获取配置详情
     */
    @ApiOperation(value = "获取配置详情")
    @GetMapping("/detail/{configId}")
    public JsonResult<SysMessageConfig> getDetail(@PathVariable(value = "configId") Long configId){
        return sysMessageConfigService.getDetail(configId);
    }

    /**
     * 配置分页
     */
    @ApiOperation(value = "配置分页")
    @PostMapping("/page")
    public JsonResult<Page<SysMessageConfig>> getPage(@RequestBody SysMessageConfig config){
        Page<SysMessageConfig> resultPage = sysMessageConfigService.page(config,new QueryWrapper<>());
        return JsonResult.success(resultPage);
    }

    /**
     * 配置更新
     */
    @ApiOperation(value = "配置更新")
    @PostMapping("/update")
    public JsonResult update(@RequestBody SysMessageConfig config){
        return sysMessageConfigService.configUpdate(config);
    }

    @ApiOperation("推送移动云消息")
    @GetMapping("/plush/moveCloudMessage")
    public void plushMoveCloudMessage(@RequestParam NotifyType messageType, @RequestParam String userName, @RequestParam String message,@RequestParam String messageUrl) throws IOException, NoSuchAlgorithmException, KeyManagementException {
        moveCloudBusiness.sendMoveCloudMessage(messageType,userName,message,messageUrl);
    }

    @ApiOperation("推送移动云消息")
    @GetMapping("/plush/moveCloudMessage/ceshi")
    public void ceshiPlushMoveCloudMessage(@RequestParam String messageType, @RequestParam String userName, @RequestParam String message,@RequestParam String messageUrl) throws IOException, NoSuchAlgorithmException, KeyManagementException {
        moveCloudBusiness.ceshiPlushMoveCloudMessage(messageType,userName,message,messageUrl);
    }

}
